package com.example.file_management.mapper.material;

import com.example.file_management.pojo.material.Project;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import org.apache.ibatis.annotations.*;
import org.yaml.snakeyaml.events.Event;

import java.util.List;

@Mapper
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
public interface ProjectMapper {

    @Insert("INSERT INTO project_table (name, owner_id, owner_name, created_at, due_date, description) " +
            "VALUES (#{name}, #{ownerId}, #{ownerName}, #{createdAt}, #{dueDate}, #{description})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertProject(Project project);

    @Select("SELECT * FROM project_table WHERE project_id = #{projectId}")
    Project getProjectById(Long projectId);

    @Select("SELECT * FROM project_table")
    List<Project> getAllProjects();

    @Update("UPDATE project_table SET name = #{name}, owner_id = #{ownerId}, owner_name = #{ownerName}," +
            "due_date = #{dueDate}, description = #{description} WHERE project_id = #{projectId}")
    int updateProject(Project project);

    @Delete("DELETE FROM project_table WHERE project_id = #{projectId}")
    int deleteProject(Long projectId);
}